﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        #result {
            width: 200px;
            height: 100px;
            border: solid 1px #90b;
        }
    </style>
</head>
<body>
    <button>点击发送</button>

    <script>
        const btns = document.querySelectorAll('button');

        let x = null;
        //表示变量
        let isSending = false;//示符正在发送AJAX请求

        btns[0].onclick = function () {
            if (isSending) x.abort();//如果为true,取消上一个请求
            x = new XMLHttpRequest();
            //修改标识变量的值
            isSending = true;
            x.open('GET', 'http://127.0.0.1:8000/delay');
            x.send();
            x.onreadystatechange = function () {
                if (x.readyState === 4) {
                    //修改标识变量
                    isSending = false;
                }
            }
        }

    
    </script>
</body>
</html>